import tkinter as tk
from tkinter import ttk
from view.panel.script1 import Script1Class
from view.panel.script2 import Script2Class


class Application(tk.Tk):
    def __init__(self):
        super().__init__()
        self.title("Script Selector")

        # 顶部选择框
        self.script_selector_label = ttk.Label(self, text="Select Script:")
        self.script_selector_label.pack(pady=10)
        self.script_var = tk.StringVar()
        self.script_var.set("Script 1")
        self.script_selector = ttk.Combobox(self, textvariable=self.script_var, values=["Script 1", "Script 2"],
                                            state="readonly", width=15)
        self.script_selector.pack()

        # 中间面板显示区域
        self.panel_frame = ttk.Frame(self)
        self.panel_frame.pack(padx=10, pady=10, fill=tk.BOTH, expand=True)

        # 底部日志框
        self.log_box = tk.Text(self, height=10, wrap=tk.WORD)
        self.log_box.pack(fill=tk.BOTH, expand=True, padx=10, pady=10)

        # 实例化并显示默认面板
        self.current_feature = None
        self.load_script_panel()

        # 绑定选择框事件
        self.script_selector.bind("<<ComboboxSelected>>", self.load_script_panel)

    def load_script_panel(self, event=None):
        # 清空当前面板
        for widget in self.panel_frame.winfo_children():
            widget.destroy()

        # 获取选择的脚本
        selected_script = self.script_var.get()

        # 根据选择的脚本加载对应的面板
        if selected_script == "Script 1":
            self.current_feature = Script1Class(self.panel_frame)
        elif selected_script == "Script 2":
            self.current_feature = Script2Class(self.panel_frame)

        # 绑定日志显示框
        if self.current_feature:
            self.current_feature.set_log_display(self.log_box)


if __name__ == "__main__":
    app = Application()
    app.mainloop()
